package tp1.tests;

import Utils.StringUtil;
import junit.framework.TestCase;

public class StringUtilTest extends TestCase {

	public void testCompare()
	{
		String s1 = null;
		String s2 = null;
		int comp = -1;

		s1 = "a";
		s2 = "b";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);
	 
		s1 = "a0";
		s2 = "b";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);
		
		s1 = "a99999999999999999999";
		s2 = "a";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "a_";
		s2 = "b";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);
		
		s1 = "abc";
		s2 = "abcd";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);
		
		s1 = "abcd";
		s2 = "abcd";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.IGUAL);

		s1 = "abcdf";
		s2 = "abcd";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "b";
		s2 = "azZZZZZZZZZZ999999999";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "azZZZZZZZZZZ999999999_";
		s2 = "azZZZZZZZZZZ999999999_";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.IGUAL);
		
		s1 = "a100";
		s2 = "a50";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "a100";
		s2 = "a180";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);
		
		s1 = "a50";
		s2 = "a7";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);
		
		s1 = "a50";
		s2 = "a51";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);

		s1 = "a180";
		s2 = "a165";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "a180";
		s2 = "a400";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);

		s1 = "a200";
		s2 = "a90";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

		s1 = "a7";
		s2 = "a100";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);

		s1 = "a70";
		s2 = "a100";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MENOR);

		s1 = "a700";
		s2 = "a100";
		comp = StringUtil.compare(s1, s2);
		assertTrue(comp == StringUtil.MAYOR);

	}

	private void imprimir(String s1, String s2,int comp)
	{
		System.out.println("-------------------------------------------");
		System.out.print("s1: [" + s1 + "] = " );
		for (byte b : s1.getBytes()) 
		{
			System.out.print(" " + b );	
		}

		System.out.print("\ns2: [" + s2 + "] = " );
		for (byte b : s2.getBytes()) 
		{
			System.out.print(" " + b );	
		}
		
		System.out.println("\n");
		
		if( comp  == StringUtil.MENOR )
			System.out.println(s1+" < " + s2);
		else if (comp == StringUtil.IGUAL)
			System.out.println(s1+" = " + s2);
		else
			System.out.println(s1+" > " + s2);
	}

}
